package com.qk.management.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.qk.common.PageResult;
import com.qk.entity.Activity;
import com.qk.management.mapper.ActivityMapper;
import com.qk.management.service.ActivityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

/**
 * @文件名: ActivityServiceImpl
 * @作者: DX
 * @创建日期: 2025/10/9
 * @描述:
 */
@Service
public class ActivityServiceImpl implements ActivityService {

    @Autowired
    private ActivityMapper activityMapper;

    @Override
    public void update(Activity activity) {
        activity.setUpdateTime(LocalDateTime.now());
        activityMapper.update(activity);
    }

    @Override
    public List<Activity> listByType(Integer type) {
        return activityMapper.listByType(type);
    }

    @Override
    public Activity getById(Integer id) {
        return activityMapper.getById(id);
    }

    @Override
    public void add(Activity activity) {
        activity.setCreateTime(LocalDateTime.now());
        activity.setUpdateTime(LocalDateTime.now());
        activityMapper.add(activity);
    }


    @Override
    public void delete(Integer id) {
        activityMapper.delete(id);
    }

    @Override
    public PageResult<Activity> pageResult(Integer channel, Integer type, Integer page, Integer pageSize) {
        PageHelper.startPage(page, pageSize);
        List<Activity> list = activityMapper.pageResult(channel, type);
        Page<Activity> pageInfo = (Page<Activity>)list;
        return PageResult.<Activity>builder()
                .total(Long.valueOf(pageInfo.getTotal()).intValue())
                .rows(pageInfo.getResult())
                .build();
    }

}
